package departmentServlet;


import javaBean.departmentDTO;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class showDepartment{
    public List showDepartment() {
        List<departmentDTO> list = new ArrayList<departmentDTO>();

        java.sql.Connection conn = null;
        java.sql.Statement sqlStmt = null;
        ResultSet rs = null;
        try {
            Class.forName("org.h2.Driver");
            conn = java.sql.DriverManager.getConnection("jdbc:h2:~/jpa-demo-db;MODE=MYSQL;DB_CLOSE_DELAY=-1", "sa", "sa");
            sqlStmt = conn.createStatement();
            rs = sqlStmt.executeQuery("select * from part");//选择import java.sql.ResultSet

            while (rs.next()) {
                departmentDTO departmentdto= new departmentDTO();
                departmentdto.setDepartment_number(rs.getString(1));
                departmentdto.setDepartment_name(rs.getString(2));
                list.add(departmentdto);
            }
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }
        return list;
    }
}
